package chap10collection.test22;

import java.util.Objects;

/**
 * @author zdl
 * @date 2024/12/17
 */
class Worker{
    private final Long id =123l;
    private String name;
    private double salary;
    private int age;

    public Worker() {
    }

    public Worker(Long id, String name, double salary, int age) {
        //this.id = id;
        this.name = name;
        this.salary = salary;
        this.age = age;
    }

    //构造方法„
//get/set 方法„
    public boolean equals(Object obj){
//1 此处仅判断 id 是否相同
        Worker w = (Worker) obj;
        return this.id == w.id;
    }
    public int hashCode(){
//2 此处返回 hashCode
        return id.hashCode();
        //return (int)(name.hashCode() + id.hashCode() + age + salary);
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return salary
     */
    public double getSalary() {
        return salary;
    }

    /**
     * 设置
     * @param salary
     */
    public void setSalary(double salary) {
        this.salary = salary;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "Worker{id = " + id + ", name = " + name + ", salary = " + salary + ", age = " + age + "}";
    }
}
public class Demo22 {
}
